<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="__STATIC__/template/favicon.ico" >
    <link rel="Shortcut Icon" href="__STATIC__/template/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="__STATIC__/template/lib/html5shiv.js"></script>
    <script type="text/javascript" src="__STATIC__/template/lib/respond.min.js"></script>

    <![endif]-->
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/lib/Hui-iconfont/1.0.8/iconfont.css" />

    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="__STATIC__/template/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->
    <!--css 加载 -->
    {load file='_CSS_/diyUpload.css'}
    {load file='_CSS_/webuploader.css'}

    <link href="__STATIC__/template/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
</head>
<body>
<nav class="breadcrumb">
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>

<div class="page-container">

    <form action="" method="post" class="form form-horizontal" id="form-article-add" >
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$result.title?$result.title:''}" placeholder="必填" id="title" name="title">
            </div>
            <span id="title_tip"></span>
        </div>
        <!--图片上传-->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>图片上传：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="weui-uploader__bd test" id="test"></div>
                <span id="filename" style="vertical-align: middle">限3张</span>
                {notempty name='result'}

                    {foreach name='$result.image' item='v'}
                    <div style="width:220px;height:120px;text-align: center">
                        <img width="110" height="100px" class="picture-thumb" src="__UPLOADS__/{$v}">
                        <a class="imgDel" data-img="{$v}" href="javascript:;">
                            删除
                        </a>
                    </div>
                    {/foreach}
                {/notempty}
            </div>
        </div>
        <!--图片上传-->

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>下载地址：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$result.link?$result.link:''}" placeholder="必填" id="link" name="link">
            </div>
            <span id="link_tip"></span>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">

                {notempty name='result'}
                <input type="hidden" value="{$result.id}" id="invite_id">
                <button onClick="invite_edit_submit();" class="btn btn-primary radius" type="button" >
                    <i class="Hui-iconfont">&#xe632;</i> 修改
                </button>
                {else /}
                <button onClick="code_save_submit();" class="btn btn-primary radius" type="button" id="submit">
                    <i class="Hui-iconfont">&#xe632;</i> 提交
                </button>

                {/notempty}

                <button  class="btn btn-default radius" type="reset">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>

</div>


<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__STATIC__/template/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/layer/2.4/layer.js"></script>
<!--<script type="text/javascript" src="__STATIC__/template/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/static/h-ui.admin/js/H-ui.admin.js"></script> -->
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->

<!-- 加载js -->
{load file='_LIB_/jquery-2.1.4.js'}
{load file='_LIB_/fastclick.js'}
{load file='_JS_/jquery.Spinner.js'}
{load file='_JS_/jquery-weui.js'}
{load file='_LIB_/diyUpload.js'}
{load file='_LIB_/webuploader.min.js'}
<script type="text/javascript">
    var image="";
    $(document).ready(function(){
        $('.imgDel').click(a_image_del);

        // image图片上传
        var obj = $('.imgDel');
        var l   = obj.length;
        if(l<3){
            var limit = 3-l;
            $("#test").diyUpload({
                url:"{:url('admin/Uploads/index')}",
                fileNumLimit:limit,
                success:function( data ) {
                    console.log( data.img );
                    if(data.ok){
                        image += data.img+',';
                        $('#filename').text('上传成功！').css('color','green');
                        return img_tip  = true;
                    }else{
                        $('#filename').text(err.msg).css('color','red');
                        return img_tip  = false;
                    }

                },
                error:function( err ) {
                    console.info( err );
                    $('#filename').text(err).css('color','red');
                    return img_tip  = false;


                }
            });
        }

    });

    /* 图片删除 */
    function a_image_del(){
        // alert(1);

        var link = $(this);
        link.parent().remove();
        var arr = new Array();
        $('.imgDel').each(function(e){
            arr.push((this). attr('data-img'))
        });

        var L = arr.length;
        var sum  = 3-L;
        alert(L+'+'+sum);
        $("#test").diyUpload({
            url:"{:url('admin/Uploads/index')}",
            fileNumLimit:sum,
            success:function( data ) {
                console.log( data.img );
                if(data.ok){
                    image += data.img+',';
                    $('#filename').text('上传成功！').css('color','green');
                    return img_tip  = true;
                }else{
                    $('#filename').text(data.msg).css('color','red');
                    return img_tip  = false;
                }

            },
            error:function( err ) {
                console.info( err );
                $('#filename').text(err).css('color','red');
                return img_tip  = false;


            }
        });
    }

    /*添加*/
    function code_save_submit(){
        var title = $('#title').val();
        var link  = $('#link').val();
        var data  = {
            image:image,
            title:title,
            link:link
        };

        $.post("{:url('code_hold')}",data,function(res){
            console.log(res);
            if(res.ok){
                layer.msg(res.msg,{icon: 1,time:2000});
                setTimeout(window.location.href="{:url('index')}",2000);
            }else{
                layer.msg(res.msg,{icon: 5,time:2000});
            }
        })

    }

    /*轮播图-修改*/
    function invite_edit_submit(){
        var title = $('#title').val();
        var link  = $('#link').val();
        var id    = $('#invite_id').val();

        var imgDel = '';
        $('.imgDel').each(function(e){
            imgDel += $(this). attr('data-img')+',';
        });

        var image_img =imgDel+image;

        var data  = {
            id:id,
            title:title,
            link:link,
            image:image_img,
        };

        $.post("{:url('code_save')}",data,function(res){
            // console.log(res);
            if(res.ok){
                layer.msg(res.msg,{icon: 1,time:2000});
                setTimeout(window.location.href="{:url('index')}",2000);
            }else{
                layer.msg(res.msg,{icon: 5,time:2000});
            }
        })


    }


</script>
</body>
</html>